class ContactForm < Form
  text_field :subject, :max_length => 100
  text_field :message
  email_field :sender
  boolean_field :cc_myself
end

f = ContactForm.new
f.bound? #=> false

data = {
  :subject => 'hello',
  :message => 'Hi there',
  :sender => 'foo@example.com',
  :cc_myself => true
}

f = ContactForm.new(data)
f.bound? #=> true
f.valid? #=> true
f.render # or f.render_table

# <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" value="hello" /></td></tr>
# <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" value="Hi there" /></td></tr>
# <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" value="foo@example.com" /></td></tr>
# <tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" checked="checked" /></td></tr>

f.render_p

# <p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>
# <p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>
# <p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>
# <p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>

f.render_ul

# <li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>
# <li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>
# <li><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li>
# <li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>

f = ContactForm.new({})
f.bound? #=> true
f.valid? #=> false (invalid email)
f.errors #=> {:sender => 'Enter a valid e-mail address.'}


